﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using LSBLL;
using LSEntity;
using LSUtility;
using OralExamBLL;
using OralExamEntity;

namespace LSWeb.Areas.OralExam.Controllers
{
    [OEAuthorizeStudent]
    public class StudentController : ControllerCommon<OEControllerFormat<OEStudentControllerFormatBLL, OEStudent.Common>, OEStudentControllerCheck, OEStudent.Common>
    {
        //
        // GET: /OralExam/Student/

        public ActionResult Index()
        {
            //var list = QuestionBLL.QuestionTypeForOTGetList(10015);
            //var qlist = QuestionBLL.QuestionForOTGetList(10014);
            //var group = qlist.QuestionForOTListSetGroup();
            return View(new OEStudent.Index
                            {
                                Common = CommonModel,
                            });
        }

        public ActionResult TestList()
        {
            return View(new OEStudent.TestList
                            {
                                Common = CommonModel,
                                TestClassList =
                                    TestBLL.TestGetClassGetList(Member.MyClass.ClassId),
                            });
        }

        public ActionResult Test(int testId)
        {
            if (TestBLL.TestOTCurrent != null &&
                TestBLL.TestOTCurrent.TestClassEntity != null &&
                TestBLL.TestOTCurrent.TestClassEntity.TestId == testId)
            {
                return View(new OEStudent.Test { Common = CommonModel, });
            }
            return Content("参数错误");
        }

        public ActionResult TestCheck(int testId, string password)
        {
            var result = (TestingStatus)Check(testId, password, true);
            return Content(ResultMessage.ResultMessageJson((int)result, result.ObjGetDescription()));
        }

        public ActionResult SetMyTest(int testId)
        {
            OECache<TestStepEntity>.TestStepSetCache(Member,
                                                     testId,
                                                     isLogin: true);

            return Content(ResultMessage.ResultMessageJson(1, "成功"));
        }

        public ActionResult MyAccount()
        {
            return View(new OEStudent.MyAccount
                            {
                                Common = CommonModel,
                                Born = Member.Born.ToString("yyyy-MM-dd"),
                                Email = Member.Email,
                                Gender = Member.Gender,
                                Mobile = Member.Mobile,
                                UserName = Member.RealName,
                                UserNum = Member.Account,
                            });
        }

        [HttpPost]
        public ActionResult MyAccount(OEStudent.MyAccount model)
        {
            var result = MemberBLL.MemberModiby(Member.AccountId,
                                                model.Email,
                                                model.Born.String2DateTime(),
                                                model.UserName,
                                                model.Gender,
                                                model.Mobile);
            return Content(ResultMessage.ResultMessageJson(result ? 1 : 0, result ? "成功" : "失败"));
        }
    }
}
